<template>
  <div class="indexPage">
    <!-- 未登录部分 -->
    <div class="loginPage"
         v-if="showModel">
      <div class="model">
        <div class="modleContent">
          <div class="modelTitle">
            <img :src=info>
          </div>
          <div class="modelBody">微信登录需要获取您的用户信息，请前往设置</div>
          <div class="btns">
            <button open-type="getUserInfo"
                    class="agree"
                    lang="zh_CN"
                    @getuserinfo="getUser">{{setting}}</button>
          </div>
        </div>
      </div>
    </div>
    <!-- 登录部分显示首页 -->
    <div class="indexMain"
         v-else>
      <div class="topSelected">
        <p class="topCheck">
          查看全面成绩预测
        </p>
        <p class="topChoise"
           @click.stop="NavexamRomm">
          <router-link :to="{name:'examinationRoom'}">
            {{subject}}
            <span>
            <img :src=imageList.selectType
                 alt="">
          </span>
          </router-link>
        </p>
      </div>
      <div class="topBg">
        <img :src=imageList.color
             class="bgImg">
        <div class="topOpition">
            <div class="listItem"
                 @click.stop="acss">
              <router-link :to="{name:'ExerciseMain'}">
                <img :src=imageList.option1
                     alt="">
                <span>课后练习</span>
              </router-link>
            </div>
          <div class="listItem"
               @click.stop="navToTraning">
            <router-link :to="{name:'exerciseTest'}">
                <img :src=imageList.option2
                     alt="">
                <span>强化训练</span>
            </router-link>
          </div>
          <div class="listItem"
               @click.stop="navTosimulation">
            <img :src=imageList.option3
                 alt="">
            <span>模拟考试</span>
          </div>
          <div class="listItem"
               @click.stop="navTorecord">
            <img :src=imageList.option4
                 alt="">
            <span>考试记录</span>
          </div>
          <div class="listItem"
               @click.stop="navToCollect">
            <img :src=imageList.option5
                 alt="">
            <span>习题收藏</span>
          </div>
          <div class="listItem"
               @click.stop="navToScore">
            <img :src=imageList.option6
                 alt="">
            <span>成绩单</span>
          </div>
        </div>
      </div>
      <div class="exam">
        <img :src=imageList.exam
             alt="">
        <span>正在考试</span>
      </div>
      <div class="examWrap">
        <div class="examList">
          <ul class="examListUl">
            <li @click.stop='navToFormal(item.id,item.name)'
                v-for="(item,index) in formalPaper"
                :key=index>
              <div class="liTop">
                <div class="leftHexagon">
                  <img :src=imageList.border
                       alt="">
                  <p class="examTitle">{{item.name}}</p>
                </div>
                <p class="play">
                  <img :src=imageList.study
                       alt="">
                </p>
              </div>
              <div class="ctTime">
                {{item.add_time}}
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import { mapState, mapMutations } from 'vuex'
  import { formatTime } from '../../utils'
  export default {
    data () {
      return {
        activeIndex: 1,
        subject: '中级人力资源',
        imageList: {
          selectType: './../../static/images/selected.png',
          color: './../../static/images/color.jpg',
          option1: './../../static/images/option1.jpg',
          option2: './../../static/images/option2.jpg',
          option3: './../../static/images/option3.jpg',
          option4: './../../static/images/option4.jpg',
          option5: './../../static/images/option5.jpg',
          option6: './../../static/images/option6.jpg',
          exam: './../../static/images/exam.jpg',
          border: './../../static/images/border.png',
          study: './../../static/images/study.png'
        },
        formalPaper: [],
        disabled: false,
        initId: 0,
        show: true,
        text: '',
        telError: false,
        setting: '去设置',
        inputType: 'password',
        password: '',
        showPassword: false,
        passwordError: false,
        info: './../../static/images/info.jpg',
        showModel: false,   // 21:33  记得修改回
        totalArea: [],
        originData: -1
      }
    },
    computed: {
      ...mapState({
        currentExam: state => state.currentExam
      })
    },
    methods: {
      ...mapMutations(['setExamSubject', 'setExamPaper', 'setUserInfo']),
      checktel (str) {
        var reg2 = /^(((13|14|15|18|17)\d{9}))$/
        if (!reg2.test(str)) {
          return false
        }
        return true
      },
      checkTel () {
        if (!this.checktel(this.text)) {
          this.telError = true
        }
      },
      addActive () {
        if (this.activeIndex === 0) {
          this.activeIndex = 1
        } else {
          this.activeIndex = 0
        }
      },
      navToLogin () {

      },
      NavexamRomm () {
        if (localStorage.getItem('openId')) {
          if (localStorage.getItem('user_id')) {
            if (localStorage.getItem('user_id') > 0) {
              this.showModel = false
//              wx.navigateTo({
//                url: '../examinationRoom/main?id=' + (this.currentExam.currentId || this.initId)
//              })
            }
          } else {
            this.showModel = true
          }
        } else {
          this.showModel = true
        }
      },
      acss () {
        if (localStorage.getItem('openId')) {
          if (localStorage.getItem('user_id')) {
            if (localStorage.getItem('user_id') > 0) {
              this.showModel = false
//              wx.navigateTo({
//                url: '../exercise/main'
//              })
            }
          } else {
            this.showModel = true
          }
        } else {
          this.showModel = true
        }
      },
      navToTraning () {
        if (localStorage.getItem('openId')) {
          if (localStorage.getItem('user_id')) {
            if (localStorage.getItem('user_id') > 0) {
              this.showModel = false
//              wx.navigateTo({
//                url: '../hardTraining/main?type=2'
//              })
            }
          } else {
            this.showModel = true
          }
        } else {
          this.showModel = true
        }
      },
      navTosimulation () {
        if (localStorage.getItem('openId')) {
          if (localStorage.getItem('user_id')) {
            if (localStorage.getItem('user_id') > 0) {
              this.showModel = false
//              wx.navigateTo({
//                url: '../examPaper/main?type=1' + '&roomId=' + (this.currentExam.roomIndex || 0)
//              })
            }
          } else {
            this.showModel = true
          }
        } else {
          this.showModel = true
        }
      },
      navTorecord () {
        if (localStorage.getItem('openId')) {
          if (localStorage.getItem('user_id')) {
            if (localStorage.getItem('user_id') > 0) {
              this.showModel = false
//              wx.navigateTo({
//                url: '../examRecord/main'
//              })
            }
          } else {
            this.showModel = true
          }
        } else {
          this.showModel = true
        }
      },
      navToCollect () {
        if (localStorage.getItem('openId')) {
          if (localStorage.getItem('user_id')) {
            if (localStorage.getItem('user_id') > 0) {
              this.showModel = false
//              wx.navigateTo({
//                url: '../collect/main'
//              })
            }
          } else {
            this.showModel = true
          }
        } else {
          this.showModel = true
        }
      },
      navToScore () {
        if (localStorage.getItem('openId')) {
          if (localStorage.getItem('user_id')) {
            if (localStorage.getItem('user_id') > 0) {
              this.showModel = false
//              wx.navigateTo({
//                url: '../score/main'
//              })
            }
          } else {
            this.showModel = true
          }
        } else {
          this.showModel = true
        }
      },
      navToFormal (index, name) {
        if (localStorage.getItem('openId')) {
          if (localStorage.getItem('user_id')) {
            if (localStorage.getItem('user_id') > 0) {
              this.showModel = false
              this.setExamPaper({
                paperName: name
              })
            }
          } else {
            this.showModel = true
          }
        } else {
          this.showModel = true
        }
      },
      init (index) {
        let that = this
        that.formalPaper = []
//        console.log(that.$mp.query.id)
        this.originData = index
        this.axios.get('/api/exam/index/')
          .then(function (res) {
            console.log(res)
            if (res.data.code === '0000') {
              that.totalArea = res.data.data
              that.subject = res.data.data[index].name
              that.initId = res.data.data[index].id
              console.log('initId', that.initId)
              for (var i = 0; i < res.data.data.length; i++) {
                if (res.data.data[i].id === that.initId) {
                  for (let k in res.data.data[i].papers) {
                    that.formalPaper.push(res.data.data[i].papers[k])
                  }
                }
              }
              for (let k in that.formalPaper) {
                that.formalPaper[k].add_time = formatTime(that.formalPaper[k].add_time)
              }
            }
          })
      },
      getUser (e) {
        var $this = this
        this.setting = '请稍后'
      }
    },
    mounted () {
        console.log(localStorage)
      if (localStorage.getItem('openId') && localStorage.getItem('user_id')) {
        this.showModel = false
      }
      this.init(0)
    },
//    onShow () {
//      console.log('onshow', this.currentExam.roomIndex)
//      if (this.originData !== this.currentExam.roomIndex && this.currentExam.roomIndex !== undefined) {
//        this.init(this.currentExam.roomIndex)
//        console.log('changeIndex')
//      }
//      this.subject = this.currentExam.currentName || '国机党建'
//    }
  }
</script>
<style lang="stylus">
  .indexMain {
  // background white
    height: 100%;
  }

  .indexPage {
    height: 100%;
  }

  .topSelected {
    height: 2.40rem;
    background: linear-gradient(#00cc76, #1eda8b, #32e098);
  // background #00cc76
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
    padding: 0 0 0 .32rem;
    justify-content: space-between;
    flex-wrap: wrap;

    .topCheck {
      color: white;
      font-size: .36rem;
    }

    .topChoise {
      color: white;
      font-size: .28rem;
      padding: .20rem;
      border-top-left-radius: .33rem;
      border-bottom-left-radius: .33rem;
      background: rgba(0, 0, 0, 0.3);
      position: relative;

      span {
        padding-left: .20rem;

        img {
          width: .32rem;
          height: .32rem;
        }
      }
    }
  }

  .topBg {
    width: 100%;
    height: 4.44rem;
    position: relative;

    .bgImg {
      width: 100%;
      height: 1.81rem;
      position: absolute;
      left: 0;
      top: 0;
      z-index: -1;
    }

    .topOpition {
      position: absolute;
      display: -webkit-box;
      display: -webkit-flex;
      display: flex;
      -webkit-box-align: center;
      -webkit-align-items: center;
      align-items: center;
      justify-content: space-around;
      flex-wrap: wrap;
      z-index: 1;
      height: 100%;
      background: white;
      left: .32rem;
      right: .32rem;
      padding-top: .55rem;
      border-radius: .12rem;
      -webkit-border-radius: .12rem;
      box-sizing: border-box;
      -webkit-box-sizing: border-box;

      .listItem {
        width: 33.33%;

        img {
          width: 1.00rem;
          height: 1.00rem;
          display: block;
          margin: 0 auto;
        }

        span {
          text-align: center;
          font-size: .30rem;
          color: #333333;
          display: block;
          padding: .20rem 0;
        }
      }
    }
  }

  .exam {
    padding: 0rem .32rem;
    height: 1.65rem;
    position: relative;
    margin: .50rem 0;

    img {
      width: 6.86rem;
      height: 1.86rem;
    }

    span {
      position: absolute;
      left: 1.20rem;
      top: .32rem;
      font-size: .36rem;
      color: white;
      font-weight: bold;
    }

    &:after {
      position: absolute;
      left: 1.20rem;
      top: 1.00rem;
      content: '';
      width: .55rem;
      height: .6rem;
      background: white;
    }
  }

  .examListUl {
    margin: 0 .32rem;
    height: 3.00rem;

    li {
      padding-top: .18rem;
      padding-bottom: 0;
      border-bottom: .02rem solid #e6e6e6;

      .liHide:nth-child(1) {
        padding-top: 0;
      }
    }
  }

  .liTop {
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
    padding-bottom: .16rem;
    .leftHexagon {
      width: .29rem;
    // height .34rem
      position: relative;
      flex: 1;

      img {
        width: .29rem;
        height: .34rem;
        position: absolute;
        margin-top: .10rem;
      // margin-top .30rem
      }

      .examTitle {
        font-size: .30rem;
        color: #000000;
        padding-left: .56rem;
        display: inline-block;
      }
    }
  }

  .play {
    width: .45rem;
    height: .45rem;
    float: right;

    img {
      width: .45rem;
      height: .45rem;
      margin-top: .30rem;
    }
  }

  .ctTime {
    padding-bottom: .17rem;
    border-left: 0;
    padding-left: .60rem;
    font-size 0.28rem
  }

  .liHide {
    font-size: .26rem;
    color: #333333;
    position: relative;
  // margin-top 8rem
    padding: .18rem 0;
    padding-left: .60rem;
    height: .32rem;

    &:before {
      position: absolute;
      content: '';
      left: .08rem;
      top: 50%;
      width: .16rem;
      height: .16rem;
      border-radius: .16rem;
      background: #00cc76;
      z-index: 2;
    }

    &:after {
      position: absolute;
      content: '';
      left: .14rem;
      top: calc(50% + .20rem);
      width: .02rem;
      height: .36rem;
      background: #00cc76;
      z-index: 1;
    }
  }

  .subTitle {
    padding-left: .20rem;
  }

  .subPlay {
    width: .32rem;
    height: .32rem;
    float: right;
    margin-right: .06rem;

    img {
      width: .32rem;
      height: .32rem;
    }
  }

  .liLast {
    &:after {
      position: absolute;
      content: '';
      left: .14rem;
      top: .20rem;
      width: 0rem;
      height: .36rem;
      background: #00cc76;
    }
  }

  .hideExamContent {
    display: none;
  }

  li.active {
    padding-bottom: .30rem;
  }

  li.active .hideExamContent {
    display: block;
  }

  li.active .ctTime {
    border-left: .02rem solid #00cc76;
  }

  .model {
    width: 100%;
    height: 100%;
    position: fixed;
    left: 0;
    top: 0;
    background: white;
    z-index: 50;
  }

  .loginPage {
    width: 100%;
    height: 100%;
  }

  .loginWrap {
    width: 100%;
    height: 100%;
    /* background-image: url("../images/login.jpg"); */
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: relative;
  }

  .loginWrap .loginZoom, .loginWrap .fillPassword {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
  }

  .loginTitle {
    font-size: 0.38rem;
    color: white;
    font-weight: bold;
    text-align: center;
    padding: 1.4rem 0;
    background: #00cc75;
    position: relative;
  }

  .loginTitle:after {
    position: absolute;
    bottom: 0;
    left: 50%;
    content: '';
  }

  .loginArea {
    margin: 0 0.76rem;
  }

  .loginInput {
    position: relative;
    height: 0.8rem;
  }

  #androidDialog1 {
    display: none;
  }

  .loginArea {
    margin-top: 0.65rem;
  }

  .loginArea input {
    width: 100%;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    padding-left: 0.3rem;
    height: 0.8rem;
    border-radius: 0.1rem;
    -webkit-border-radius: 0.1rem;
    font-size: 0.34rem;
    border: none;
    outline: none;
  }

  .loginInput input {
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 3px 5px #ccc;
  }

  ::-webkit-input-placeholder { /* WebKit browsers */
    color: #999;
    font-size: 0.3rem;
  }

  .loginInput .errorTips {
    position: absolute;
    right: 0.6rem;
    top: 0;
    height: 100%;
    padding-right: 0.6rem;
    background-image: url('https://xcx.taosha.co/Uploads/images/errorTips.png');
    background-repeat: no-repeat;
    background-position: right center;
    background-size: 0.3rem 0.3rem;
    font-size: 0.24rem;
    color: #e83328;
    line-height: 0.8rem;
    z-index: 999;
    /* display: none; */
  }

  .loginInput .eyes {
    position: absolute;
    right: 0.3rem;
    top: 0;
    height: 100%;
    width: 0.68rem;
    background-image: url('https://xcx.taosha.co/Uploads/images/eyes2.png');
    background-size: 0.38rem 0.24rem;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 999;
    /* display: none; */
  }

  .loginBtn {
    width: 100%;
    height: 0.8rem;
    margin-top: 0.3rem;
  }

  .loginBtn input {
    text-align: center;
    line-height: 0.8rem;
    font-size: 0.34rem;
    color: #ffffff;
    background: linear-gradient(to right, #04c373 0%, #00e999 100%);
    box-shadow: 0 3px 5px #ccc;
  }

  .loginTips {
    text-align: center;
    font-size: 0.24rem;
    color: #000;
    margin-top: 0.2rem;
  }

  // @keyframes shake {
  // from, to {
  // -webkit-transform: translate3d(0, 0, 0);
  // transform: translate3d(0, 0, 0);
  // }
  // }
  .shake {
    -webkit-animation-name: shake;
    animation-name: shake;
  }

  .animated {
    -webkit-animation-duration: 1s;
    animation-duration: 1s;
    -webkit-animation-fill-mode: both;
    animation-fill-mode: both;
  }

  .code {
    text-align: center;
    font-size: 0.24rem;
    color: white;
    padding-top: 0.13rem;
  }

  .sendCode {
    font-weight: normal;
  }

  .loginArea .codeArea {
    text-align: center;
  }

  .loginArea .codeArea input {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 0.13rem;
    background-color: rgba(255, 255, 255, 0.7);
    margin: 0 0.1rem;
  }

  .codeerrorTips {
    text-align: center;
    padding-top: 0.2rem;
    display: none;
  }

  .codeerrorTips span {
    display: inline-block;
    position: relative;
    font-size: 0.24rem;
    color: white;
    padding-left: 0.5rem;
  }

  .codeerrorTips span:before {
    position: absolute;
    content: '';
    left: 0;
    top: 50%;
    margin-top: -0.15rem;
    width: 0.3rem;
    height: 0.3rem;
    background-image: url('https://xcx.taosha.co/Uploads/images/errorTips.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 0.3rem 0.3rem;
  }

  .codeerrorTips span.noTips:before {
    width: 0;
  }

  .setPassword {
    display: none;
  }

  .fillPassword {
    /* display: none; */
  }

  .forgetPassword {
    font-size: 0.24rem;
    color: white;
    text-align: center;
    padding-top: 0.2rem;
  }

  .forgetPassword a {
    color: #000;
  }

  button[disabled] {
    color: white;
  }

  button[disabled]:not([type]) {
    color: rgba(255, 255, 255, 0.7);
    background-color: #48c4a0;
  }
</style>
